<div id="sub_nav">
    <p>Quick Links:</p>
    <ul>
        <li><a href="<?php echo Configure::read('base_url');?>backstage/invoices" title="Invoices Awaiting Payment">Invoices Awaiting Payment</a></li>
        <li><a href="<?php echo Configure::read('base_url');?>backstage/invoices/overdue_invoices" title="Overdue Invoices">Overdue Invoices</a></li>
        <li><a href="<?php echo Configure::read('base_url');?>backstage/invoices/paid_invoices" title="Paid Invoices">Paid Invoices</a></li>        
    </ul>
</div>
<div class="breadcrumb">
    <ul id="breadcrumb">
        <li><a href="<?php echo Configure::read('base_url');?>backstage" title="Home">
		<?php echo $this->Html->image("home.png", array("alt" => "Home",'class'=>'home','border'=>'0'));?>
		</a></li>
        <li><a href="<?php echo Configure::read('base_url');?>backstage/invoices"  title="Invoices">Invoices</a></li>
        <li>Overdue Invoices</li>        
    </ul>
</div>
<?php echo $this->element('admin/admin_leftmenu'); ?>
<div id="left"> 
	<br class="clear" />
	<?php echo $this->Session->flash(); ?>
	<div class="div_header"><?php __('Overdue Invoices');?></div>
	<div class="div_content">
		<?php echo $this->Form->create('Invoices', array('action' => 'index')); ?>
		<br />Select Year: <select name="data[search_year]">
		<?php 
			$reg_date=date("Y",strtotime($session->read('Auth.User.created')));
			$cur_date=date("Y");
			for($i=$reg_date;$i<=$cur_date;$i++){
			if($i==$cur_date)
				$selected=' selected="selected"';
			else
				$selected='';
		?>
		<option value="<?php echo $i;?>" <?php echo $selected;?>><?php echo $i;?></option>
		<?php } ?>
		</select>
		<?php $months=array("01"=>"January","02"=>"February","03"=>"March","04"=>"April","05"=>"May","06"=>"June","07"=>"July","08"=>"August","09"=>"September","10"=>"Octomber","11"=>"November","12"=>"December");?>
		Select Month: <select name="data[search_month]">
		<?php
			foreach($months as $key=>$value){
			if($key==date('m'))
				$selected=' selected="selected"';
			else
				$selected='';
			echo'<option value="'.$key.'" '.$selected.'>'.$value.'</option>';
			}
		?>
		</select>
		<input type="submit" name="submit" value="Generate" />
		</form>
		<?php if(!empty($invoices)): ?>
		<table width="100%" border="0" cellspacing="0" cellpadding="0" class="StateTable">
			
				<tr class="statetablerow">
					<th style="width:139px;">Reference # / Invoice ID</th>
					<th style="width:100px;">Invoice Date</th>
					<th style="width:100px;">Invoice Due Date</th>
					<th style="width:100px;">Total Sale Amount</th>
					<th style="width:100px;">Authentic Avenue Fees</th>
					<!--th style="width:auto;">Pay Now</th-->
				</tr>	
			</table>
                <ul class="accordinginv"  style="list-style-type: none;margin: 0;padding: 0;">
                    <?php
                    $i = 0;
                    foreach ($invoices as $invoice):
                    ?>
                        <li>
                            <table width="100%" border="0" cellspacing="0" cellpadding="0" class="invoicetogle StateTable">
                                <tr id="row_<?php echo $invoice['Invoice']['id']; ?>" class="invoicehead" style="cursor:pointer;">
                                    <td width="139"><?php echo $invoice['Invoice']['id']; ?></td>
                                    <td width="100"><?php echo date("m-d-Y", strtotime($invoice['Invoice']['invoice_date'])); ?></td>
                                    <td width="100"><?php echo date("m-d-Y", strtotime($invoice['Invoice']['invoice_due_date'])); ?></td>
                                    <td width="100">$<?php echo $invoice['Invoice']['total_sale']; ?></td>
                                    <td width="100">$<?php echo $invoice['Invoice']['aa_fee']; ?></td>
                                    <!--td><?php
                        echo $this->Form->input("InvoiceId", array("type" => "hidden", "value" => $invoice['Invoice']['id']));
                    ?>
                                        <input type="image" name="submit" value="Submit" src="<?php echo Configure::read('base_url'); ?>img/paypal.gif" />
					&nbsp;&nbsp;
                                <?php
                                echo $this->Form->create('Invoice', array('action' => 'process_invoice_gcheckout'));
                                echo $this->Form->input("id", array("type" => "hidden", "value" => $invoice['Invoice']['id']));
                                ?>

                                        <input type="image" name="submit" value="gcheckout" src="<?php echo Configure::read('base_url'); ?>img/google_checkout.gif" />
					</form>
				</td-->
                            </tr>
                        </table>
                        <ul style="list-style-type: none;margin: 0;padding: 0;<?php if ($i == 0) { ?>display:block;<?php } ?>">
                            <li>
                                <table width="100%" border="0" cellspacing="0" cellpadding="0" class="StateTable">
                                    <tr>
                                        <td class="nopad" colspan="6">
                                            <?php echo $this->requestAction("invoices/fetch_invoice_order/" . $invoice['Invoice']['id'], array('return')); ?>
                                        </td>
                                    </tr>
                                </table>
                            </li>
                        </ul>
                    </li>
                    <?php
                $i++;
            endforeach; ?>
        </ul>
		<?php else:?>
		<br /><br />
		<h2>No overdue invoices found.</h2>
		<br /><br /><br />
		<?php endif;?>
		<div class="paging">
			<?php
				echo $this->Paginator->prev('<< ' . __('previous', true), array(), null, array('class'=>'disabled'));?> | 
			<?php echo $this->Paginator->numbers();?>
				| 
			<?php echo $this->Paginator->next(__('next', true) . ' >>', array(), null, array('class' => 'disabled'));?>
		</div>
    </div>
    <div class="div_bottom"></div>
</div>    
</div>
<script type="text/javascript">
jQuery('.invoicetogle').click(function(){
		var trackinv=jQuery('.invoicetogle').index(this);
		if(jQuery("ul.accordinginv li ul:eq("+trackinv+")").is(":hidden")) {
		jQuery("ul.accordinginv li ul:eq("+trackinv+")").show("slow");
		}
		else{
		jQuery("ul.accordinginv li ul:eq("+trackinv+")").hide("slow");
			}
		return false;
    });
</script>
<?php echo $this->Html->css('table_css');?>
<style type="text/css">
	table.CityTable, table.StateTable{text-align:center;width:100%;}
	table td{padding:5px;vertical-align: top;}
	table.StateTable  th{background: #E6EEEE; padding: 5px; cursor:pointer;}
	table.CityTable  th{padding: 5px; background: #C7DBF1;cursor:pointer; color:black;}	
	table.StateTable td.nopad{padding:0;vertical-align: top;}
	tr.invoicehead{padding: 5px; background: #729FDC;color:black;font-weight:700;}	
	tr.odd{background: #eee;}
	tr.headodd{padding: 5px; background: #C7DBF1;color:black;}
	tr.head1odd{padding: 5px; background: #E6EEEE;color:black;}
</style>
<style type="text/css">
td p span{color:#00B050;}
td.vendor h2 {font-size:20px; color: #00B050;}
</style>